<extend name="Base:main" />
<block name="script">
	<link rel="stylesheet" href="__PUBLIC__/seller/css/validform.css" />
	<script src="__PUBLIC__/seller/js/Validform_v5.3.2.js"></script>
</block>
<block name="content">
<div class="tpl-content-wrapper">
            <div class="tpl-content-page-title">
               <eq name="type" value="1">
               一键分销清单
               <else />
               锁库清单
               </eq>
            </div>
            <ol class="am-breadcrumb">
                <li><a href="#" class="am-icon-home">首页</a></li>
                <li><a href="#">商品管理</a></li>
                <li class="am-active">
                	<eq name="type" value="1">
                   一键分销清单列表
                   <else />
                   锁库清单列表
                   </eq>
                </li>
            </ol>
            <div class="tpl-portlet-components">
				<eq name="Think.get.type" value="lock">
				<ul class="am-tabs-nav am-nav am-nav-tabs">
					<li <eq name="Think.get.status" value="1">class="am-active"</eq><empty name="Think.get.status" >class="am-active"</empty>><a href="{:U('Goods/distribution',array('type' => 'lock'))}">正常锁货 ({$normal_count})</a></li>
					<li <eq name="Think.get.status" value="4">class="am-active"</eq>><a href="{:U('Goods/distribution',array('type' => 'lock', 'status' => 4))}">临期锁货 ({$advent_count})</a></li>
					<li <eq name="Think.get.status" value="2">class="am-active"</eq>><a href="{:U('Goods/distribution',array('type' => 'lock', 'status' => 2))}">无库存锁货 ({$nothing_count})</a></li>
					<li <eq name="Think.get.status" value="3">class="am-active"</eq>><a href="{:U('Goods/distribution',array('type' => 'lock', 'status' => 3))}">保存过期锁货 ({$overdue_count})</a></li>
				</ul>
				</eq>
                <div class="tpl-block">
                    <div class="am-g">
                      
                          <form class="am-form" action="{:U('Goods/index')}" method="get">
                              <input type="hidden" name="c" value="{$Think.const.CONTROLLER_NAME}" class="form-control">
                                <input type="hidden" name="a" value="{$Think.const.ACTION_NAME}" class="form-control">
                                <input type="hidden" name="m" value="{$Think.const.MODULE_NAME}" class="form-control">
                               <div class="am-u-sm-12 am-u-md-5">
                                   
                                  <label class=" am-form-label">商品名称</label> <span style="display: inline-block;"><input type="text"  name="keyword" value="{$sh.keyword}"  class=" am-form-field"></span>
                               
                                </div>
                              
                             
                             
                                <div class="am-u-sm-12 am-u-md-3">
                                    <div class="am-input-group am-input-group-sm">
                                         <button type="submit" class="btn btn-purple btn-sm">
                                            <span class="ace-icon fa fa-search icon-on-right bigger-110"></span>
                                            Search
                                        </button>
                                    </div>
                                </div>
                          </form>
                    </div>
                    <div class="am-g">
                        <div class="am-u-sm-12">
                          
                                <table class="am-table am-table-striped am-table-hover table-main">
                                    <thead>
                                        <tr>
                                          
                                            <th class="table-check"> <input class="check-all" type="checkbox" value=""></th>
                                            <th width="80px">分销商品ID</th>
                                            <th class="table-title"  width="260px">商品名称</th>
                                            <eq name="type" value="2">
                                            <th>供货商名称</th>
                                            </eq>
                                            <th>供货价</th>
                                            <th>销售价</th>
                                            <th>分销模式</th>
                                            <th>库存</th>
                                            <eq name="type" value="2">
                                            <th>商品位置</th>
											<neq name="Think.get.status" value="2">
                                            <th>仓库保存时间</th>
											<eq name="Think.get.status" value="3">
											<th>延期费用</th>
											</eq>
											</neq>
                                            <else />
                                            <th>供应商家</th>
                                            </eq>
                                            <th class="table-set" width="270">操作</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                      <volist name="data['list']" id="val">
                                        
                                        <tr>
                                            <td><input class="ids" type="checkbox" name="ids[]" value="{$val['id']}"></td>
                                            <td>{$val.id}</td>
                                            <td><a href="#">{$val.name}</a></td>
                                            <eq name="type" value="2">
                                            <td>{$val['supply_name']}</td>
                                            </eq>
                                            <eq name="val.type" value="2">
                                            <td>{$val['cost_price']}</td>
                                            <else />
                                            <td>{:getSupplyPriceSmall($val['goods_id'])} 至 {:getSupplyPriceMax($val['goods_id'])}</td>
                                            </eq>
                                            <td>{$val['price']}</td>
                                            <td><eq name="val.type" value="2">锁货模式<else/>共享模式</eq></td>
                                            <td>{$val['stock_num']}</td>
                                            <eq name="type" value="2">
                                            <td><eq name="val.type" value="2"><eq name="val.stock_status" value="1">在仓库<else />运送途中</eq><else/>--</eq></td>
											<neq name="Think.get.status" value="2">
											<td>{:surplus_storage_time($val['storage_end_time'])}</td>
                                            </neq>
											<eq name="Think.get.status" value="3">
											<td>{:number_format(goods_storage_overdue_money( $val['id'] ),2,".",",")}</td>
											</eq>
											<else />
                                            <td>
                                            	<div id="doc-dropdown-justify">
													<div class="am-dropdown" data-am-dropdown="{justify: '#doc-dropdown-justify'}">
														<a class="am-dropdown-toggle" data-type="close" data-id="{$val.goods_id}" id="supply_show_list">【{$val.supply_total}】家供应商 <span class="am-icon-caret-down"></span></a>
														<div class="am-dropdown-content">
															<div class="supply_lists">
																<span></span>
																<div style="clear:both"></div>
															</div>
															<gt name="val.supply_total" value="3">
															<?php
																$page_num = ceil( $val['supply_total'] / 3 );
															?>
															<div class="supply_page" style="display:none;">
															<?php for($i=1;$i<=$page_num;$i++ ) :?>
																<a href="javascript:;" data-val="{$i}"  <?php echo $i == 1 ? 'class="active"' : ''; ?>>{$i}</a>
															<?php endfor; ?>
															</div>
															</gt>
														</div>
													</div>
												</div>
                                            </td>
                                            </eq>
                                            <td>
                                                <div class="am-btn-toolbar">
                                                    <div class="am-btn-group am-btn-group-xs">
													<?php if( !isset( $_GET['status'] ) || $_GET['status'] == 1 ) : ?>
                                                    <eq name="val.type" value="2">
                                                    	<eq name="val.stock_status" value="1">
                                                        <button class="am-btn am-btn-default am-btn-xs am-text-secondary"><span class="am-icon-pencil-square-o"></span> <a href="{:U('addOrder',array('goods_id'=>$val['goods_id']))}">直接购买</a></button>
                                                        <else />
                                                        <button class="am-btn am-btn-default am-btn-xs "> <a href="javascript:;">不能购买</a></button>
                                                        </eq>
                                                    <else />
                                                        <button class="am-btn am-btn-default am-btn-xs am-text-secondary"><span class="am-icon-pencil-square-o"></span> <a href="{:U('addOrder',array('goods_id'=>$val['goods_id']))}">直接购买</a></button>
                                                    </eq>
													<?php endif; ?>
                                                        <eq name="val.type" value="2">
                                                        <button class="am-btn am-btn-default am-btn-xs am-text-secondary"><span class="am-icon-pencil-square-o"></span> <a href="{:U('LockOrder/lockStockNumList',array('goods_id'=>$val['goods_supply_id']))}" title="锁库清单" width="600" height="400" menu="load_iframe_url">锁库清单</a></button>
                                                        <neq name="Think.get.status" value="3">
														<button class="am-btn am-btn-default am-btn-xs am-text-secondary"><span class="am-icon-pencil-square-o"></span> <a href="{:U('Goods/goodsLockStock',array('id'=>$val['goods_supply_id'],'type'=>'saveLock'))}" title="补充商品锁货库存" width="600" height="500" menu="load_iframe_url">补充库存</a></button>
                                                       	<else />
														<button class="am-btn am-btn-default am-btn-xs am-text-secondary"><span class="am-icon-pencil-square-o"></span> <a href="{:U('Goods/payWarehouseStorageMoney',array('id'=>$val['id']))}" title="支付库存保管费">支付保管费</a></button>
														</neq>
														</eq>
                                                    </div>
                                                </div>
                                            </td>
                                        </tr>
                                    </volist>
                                    </tbody>
                                </table>
                                <div class="am-cf">

                                    <div class="am-fr">
                                        <ul class="am-pagination tpl-pagination">
                                            {$data['page']}
                                        </ul>
                                    </div>
                                </div>
                                <hr>
								<eq name="Think.get.status" value="3">
								<div style="width:100%;line-height:200%; color:red;">
									注意：锁货商品在仓库保存时间过期之后将无法在系统里面进行任何交易，请尽快支付延期费用以及续费您的保管时间，以免造成不必要的损失。
								</div>
								</eq>
                        </div>

                    </div>
                </div>
                <div class="tpl-alert"></div>
            </div>

        </div>
    <script id="supply_list_tempate">
	{{#  $.each(d.data, function(index, item){ }}
		<dl>
			<dt>{{ item.shop_name }}</dt>
			<dd style="width:98%;">
				<table>
					<tr>
						<td>代发价：￥{{ item.acting_price }}</td>
						<td>批发价：￥{{ item.wholesale_price }}</td>
					</tr>
					<tr>
						<td>锁库价：￥{{ item.lock_price }}</td>
						<td>库　存：{{ item.stock_num }}</td>
					</tr>
				</table>
			</dd>
		</dl>
	{{# }); }}
	</script>
    <script>
		$(document).on('click' , 'div.supply_page a',function(){
			var _self = $(this).closest( '.am-dropdown' );
			$(this).parent().find('a.active').removeClass( 'active' );
			$(this).addClass( 'active' );
			_self.find('.supply_lists').html( data_load_template );
			$.get("{:U('Goods/goodsSupplyList')}" , { goods_id : _self.find('#supply_show_list').attr('data-id') , p : $(this).attr('data-val') } , function( data ){
				if( data.status == 1 ) {
					laytpl($('#supply_list_tempate').html() ).render(data , function(html){
						_self.find('.supply_lists').html( html );
						_self.find('.supply_page').show();
					});
				} else {
					_self.find('.supply_lists').html( not_message_template );
				}
			},'json');
		});
		$('a#supply_show_list').click(function(){
			var data_type = $(this).attr('data-type') == 'close' ? 'open' : 'close';
			var data_id = $(this).attr('data-id');
			var _self = $(this).parent();
			$(this).attr( 'data-type' , data_type );
			if( data_type == 'open' ) {
				_self.find('.supply_lists').html( data_load_template );
				$.get("{:U('Goods/goodsSupplyList')}" , { goods_id : data_id} , function( data ){
					if( data.status == 1 ) {
						laytpl($('#supply_list_tempate').html() ).render(data , function(html){
							_self.find('.supply_lists').html( html );
							_self.find('.supply_page').show();
						});
					} else {
						_self.find('.supply_lists').html( not_message_template );
					}
				},'json');
			} else {
				_self.find('a.active').removeClass( 'active' );
				_self.find('.supply_page a').eq(0).addClass( 'active' );
			}
		});
		$(function () {
			var goods_type_id = $('#goods_type').val();
			if(goods_type_id){
				$('#goods_type_id option').each(function(){
					if( goods_type_id == $(this).attr('value') ) {
						$(this).attr('selected' , true);
						return false;
					} 
				}); 
			}
		})
		$(".check-all").click(function () {
			$(".ids").prop("checked", this.checked);
		});
		$(".ids").click(function () {
			var option = $(".ids");
			option.each(function (i) {
				if (!this.checked) {
					$(".check-all").prop("checked", false);
					return false;
				} else {
					$(".check-all").prop("checked", true);
				}
			});
		});
    </script>
    
</block>